﻿using AutoMapper;
using BasicInformation.API.Application.Command.OwnerCommand;
using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.OwnerCommandHandler
{
    public class OwnerCreateCommandHandler : IRequestHandler<OwnerCreateCommand, int>
    {
        private readonly IOwnerRepository ownerRepository;
        private readonly IMapper mapper;

        public OwnerCreateCommandHandler(IOwnerRepository ownerRepository, IMapper mapper)
        {
            this.ownerRepository = ownerRepository;
            this.mapper = mapper;
        }
        public async Task<int> Handle(OwnerCreateCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Owner>(request);
            return await ownerRepository.Create(info);
        }
    }
}
